﻿#region License
// Copyright (c) 2011 Saman Ranjbari
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

namespace AjaxListBox.Controls
{
    using System;
    using System.Data;
    using System.Web.UI.WebControls;
    using System.Collections;
    using System.Collections.Generic;

    public partial class MultiListBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LeftBoxWidth = "300px";
            RightBoxWidth = "300px";
            LeftBoxHeight = 365;
            RightBoxHeight = 365;
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            this.ListBoxLeft.Height = new Unit(string.Format("{0} px", LeftBoxHeight));
            this.ListBoxRight.Height = new Unit(string.Format("{0} px", RightBoxHeight));

            this.ListBoxLeft.Width = new Unit(LeftBoxWidth);
            this.ListBoxRight.Width = new Unit(RightBoxWidth);

            this.lblTitleLeft.Width = new Unit(LeftBoxWidth);
            this.lblTitleRight.Width = new Unit(RightBoxWidth);

            this.lblTitleLeft.Text = LeftBoxTitle;
            this.lblTitleRight.Text = RightBoxTitle;

            this.ListBoxLeft.DataTextField = LeftBoxDataTextField;
            this.ListBoxRight.DataTextField = RightBoxDataTextField;

            this.ListBoxLeft.DataValueField = LeftBoxDataValueField;
            this.ListBoxRight.DataValueField = RightBoxDataValueField;

            this.ListBoxLeft.DataSource = LeftBoxDataSource;
            this.ListBoxRight.DataSource = RightBoxDataSource;
            this.ListBoxLeft.DataBind();
            this.ListBoxRight.DataBind();

            this.hdnLeftClickFunction.Value = LeftClickFunction;
            this.hdnRightClickFunction.Value = RightClickFunction;

            this.hdnLeftClickExtraData.Value = LeftClickExtraData;
            this.hdnRightClickExtraData.Value = RightClickExtraData;

            this.rightArr.Style.Add("padding-top", Convert.ToInt32(RightBoxHeight) / 2 + "px");
            this.leftArr.Style.Add("padding-top", Convert.ToInt32(LeftBoxHeight) / 2 + "px");
        }

        #region Control Properties

        public string LeftBoxWidth { get; set; }

        public string RightBoxWidth { get; set; }

        public int LeftBoxHeight { get; set; }

        public int RightBoxHeight { get; set; }

        public string LeftBoxTitle { get; set; }

        public string RightBoxTitle { get; set; }

        public IList LeftBoxDataSource { get; set; }

        public IList RightBoxDataSource { get; set; }

        public string LeftBoxDataTextField { get; set; }

        public string RightBoxDataTextField { get; set; }

        public string LeftBoxDataValueField { get; set; }

        public string RightBoxDataValueField { get; set; }


        /// <summary>
        /// Server Side Method to fire after the Right arrow is clicked. 
        /// This needs to be a Web Method or web service call
        /// </summary>
        /// <value></value>
        /// <returns>Returns the message to be displayed as a notification</returns>
        public string RightClickFunction { get; set; }

        /// <summary>
        /// Server Side Method to fire after the Left arrow is clicked. 
        /// This needs to be a Web Method or web service call
        /// </summary>
        /// <value></value>
        /// <returns>Returns the message to be displayed as a notification</returns>
        public string LeftClickFunction { get; set; }

        public string LeftClickExtraData { get; set; }

        public string RightClickExtraData { get; set; }

        #endregion
    }
}